async function incrementId() {
  let maxId = 0
  try{
    maxId = await global.storage.load({key: 'maxId'});
  }catch(e) {
  }
  ++ maxId;
  await global.storage.save({
    key: 'maxId',
    data: maxId
  });
  return maxId;
}

export async function saveTfa(payload) {
  const id = await incrementId();
  const tfa = {
    ...payload,
    id,
  };
  await global.storage.save({
    key: 'tfa',
    id: id,
    data: tfa,
  });
  return tfa;
}

export async function getTfaList() {
  try{
    return await global.storage.getAllDataForKey('tfa');
  }catch(e){
    console.log(e);
  }
  return [];
}

export async function removeTfa(id) {
  await global.storage.remove({
    key: 'tfa',
    id,
  });
}